import QtQuick 1.1
//import com.nokia.symbian 1.1
import com.nokia.meego 1.0
import "platform.js" as PLATFORM

PageStackWindow {
    id: appWindow

    initialPage: mainPage

    Visual {
        id: visual
    }

    StatusBar {
        id: statusBar

        property alias text: statusText.text

        Text {
            id: statusText
            text: "NumismatMobile"
            color: visual.colorInvertedForeground
            visible: PLATFORM.TYPE === "symbian"
        }
    }

    MainPage {
        id: mainPage
    }

    DetailsPage {
        id: detailsPage
    }

    ImagePage {
        id: imagePage
    }

    ToolBarLayout {
        id: commonTools
        visible: true
        ToolIcon {
            platformIconId: "toolbar-view-menu"
            anchors.right: (parent === undefined) ? undefined : parent.right
            onClicked: (mainMenu.status === DialogStatus.Closed) ? mainMenu.open() : mainMenu.close()
        }
    }

    AboutDialog {
        id: about
    }

    FileDialog {
        id: fileDialog
        onAccepted: {
            mainPage.openDb(fileName);
        }
    }

    DownloadDialog {
        id: downloadPage
        onAccepted: {
            mainPage.openDb('file:///'+fileName);
        }
        onUpdateReady: {
            mainPage.updateDb('file:///'+fileName);
        }
    }

    SettingsPage {
        id: settingsPage
    }

    Menu {
        id: mainMenu
        visualParent: pageStack
        MenuLayout {
            MenuItem {
                text: qsTr("About")
                onClicked: about.open()
            }
            MenuItem {
                text: qsTr("Open...")
                onClicked: {
                    fileDialog.folder = 'file:///'+coinModel.folder();
                    pageStack.push(fileDialog);
                }
            }
            MenuItem {
                text: qsTr("Download...")
                onClicked: {
                    pageStack.push(downloadPage);
                }
            }
            MenuItem {
                text: qsTr("Settings")
                onClicked: {
                    pageStack.push(settingsPage);
                }
            }
            MenuItem {
                id: exitMenuItem
                text: qsTr("Exit")
                onClicked: {
                    Qt.quit();
                }
            }
        }
    }

    Component.onCompleted: {
        if (PLATFORM.TYPE === "harmattan") {
            exitMenuItem.destroy();
            theme.colorScheme = 19;
        }
        else {
            toolBar.platformInverted = true;
        }
    }
}
